package org.seedltd.upms.service.impl.detection;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.seedltd.core.base.BaseServiceImpl;
import org.seedltd.springsecurity.utils.UserUtils;
import org.seedltd.upms.mapper.detection.DetectionOrderLogMapper;
import org.seedltd.upms.model.detection.entity.DetectionOrderLog;
import org.seedltd.upms.service.detection.DetectionOrderLogService;
import org.springframework.stereotype.Service;

import lombok.AllArgsConstructor;

/**
 * 订单日志信息业务实现
 * 
 * @author laizuan
 * @since 2021/07/31
 */
@Service
@AllArgsConstructor
public class DetectionOrderLogServiceImpl extends BaseServiceImpl<DetectionOrderLogMapper, DetectionOrderLog>
    implements DetectionOrderLogService {

    @Override
    public void add(String optName, Date optTime, Long orderId, String remark) {
        DetectionOrderLog pojo = new DetectionOrderLog();
        pojo.setOptName(optName);
        pojo.setOptTime(optTime);
        pojo.setOrderId(orderId);
        pojo.setRemark(StringUtils.substring(remark, 0, 255));
        pojo.setCreateTime(new Date());
        pojo.setCreateBy(UserUtils.getUserId());
        baseMapper.insert(pojo);
    }

    @Override
    public List<DetectionOrderLog> listByOrderId(Long orderId) {
        return q().orderByDesc(DetectionOrderLog::getOptTime).eq(DetectionOrderLog::getOrderId, orderId).selectList();
    }
}